package learn.advance.filewriter1;

import sun.security.mscapi.CPublicKey;

import java.beans.FeatureDescriptor;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

class Demo1Writer {
    public static void Test() throws IOException {
        FileWriter fw = new FileWriter("D:\\workplace\\新建文件夹\\test\\a.txt");
        fw.write(97);
        fw.flush();
        fw.close();
    }
}

class Demo2Writer {
    public static void Test() throws IOException {
        FileWriter fw = new FileWriter("D:\\workplace\\新建文件夹\\test\\a.txt", true);
        char[] cs = {'a', 'b', 'c'};

        fw.write(cs);
        fw.write(cs, 1, 1);
        fw.flush();

        fw.write("传智");
        fw.flush();

        fw.write("\r\n");
        fw.write("传智");
        fw.flush();

        fw.close();
    }
}

class DemoTryCatch {
    public static void Test() {

        try (FileWriter fw = new FileWriter("D:\\workplace\\新建文件夹\\test\\a.txt");
             FileReader fr = new FileReader("D:\\workplace\\新建文件夹\\test\\b.txt");
        ) {
            int len = 0;
            while ((len = fr.read()) != -1) {
                fw.write(len);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}


public class TestFileWriter {
    public static void main(String[] args) throws IOException {
        // Demo1Writer.Test();
        // Demo2Writer.Test();
        DemoTryCatch.Test();
    }
}

